package com.kygeng.springframework.context.event;

import com.kygeng.springframework.beans.factory.BeanFactory;
import com.kygeng.springframework.context.ApplicationEvent;
import com.kygeng.springframework.context.ApplicationListener;

import java.util.Collection;

/**
 * @Title: SimpleApplicationEventMulticaster
 * @Author: kygeng
 * @Package: com.kygeng.springframework.context.event
 * @Date: 2024/8/3 16:58
 * @Description:
 */
public class SimpleApplicationEventMulticaster extends AbstractApplicationEventMulticaster {

    public SimpleApplicationEventMulticaster(BeanFactory beanFactory) {
        setBeanFactory(beanFactory);
    }

    @Override
    public void multicastEvent(final ApplicationEvent event) {
        //获取当前事件有哪些监听器
        Collection<ApplicationListener> listenerCollection = getApplicationListeners(event);
        //广播事件
        for (final ApplicationListener listener : listenerCollection) {
            listener.onApplicationEvent(event);
        }
    }

}
